package org.mozhu.mboot.core.json.jackson.jdk.ser;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;

abstract class JdkSerializerBase<T> extends StdSerializer<T> {
    private static final long serialVersionUID = 3594310226710235627L;

    protected JdkSerializerBase(Class<T> cls) {
        super(cls);
    }

    @Override
    public void serializeWithType(T value, JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer) throws IOException {
        typeSer.writeTypePrefix(jgen, typeSer.typeId(value, JsonToken.VALUE_STRING));
        serialize(value, jgen, provider);
        typeSer.writeTypeSuffix(jgen, typeSer.typeId(value, JsonToken.VALUE_STRING));
    }

}
